package cn.weekimwee.firstlineofcodeforkotlin.unit9.network

import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleOwner
import com.trello.rxlifecycle2.android.lifecycle.kotlin.bindUntilEvent
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by Wee Kim Wee on 2018/4/8.
 */

/**
 * 生命周期管理
 */
fun <T> Observable<T>.bindThreadAndLiftCircle(owner:LifecycleOwner):Observable<T>{
    return this.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .bindUntilEvent(owner, Lifecycle.Event.ON_STOP)
}